<?php

class Banner extends DataObject{
	static $db = array (
		"Name" => "Varchar(255)",
		"Content" => "Varchar(2000)",
		"LinkName" => "Varchar(2000)",
		"Link" => "Varchar(2000)",
		"Status"=> "Boolean",
	);
	static $has_one = array (
		'Banner'=>'Image',
	);
	static $searchable_fields = array (
		'Name'=> array('title'=>'Tên'),
	);
	/**
	 * Overload so that the default sort.
	 */
	static $summary_fields = array (
		'Name' => 'Tên',
		'Content' => 'Giới thiệu',
		'Link' => 'Link',
		'Status' => 'Trạng thái',
	);

	function getCMSFields($controller = null) {
		$ArticleTabVn= new Tab(_t('Support.TABCONTENTTITLEVN', 'Banner'),
		new TextField("Name", _t('Support.Name', 'Tên')),
		new TextareaField("Content", _t('Support.Content', 'Giới thiệu')),
		new TextField("LinkName", _t('Support.Name', 'Link Name')),
		new TextField("Link", _t('Support.Name', 'Link')),
		new FileIFrameField("Banner", _t('Support.Name', 'File')),
		new CheckboxField("Status",_t('Support.Status', 'Hoạt động'))
		);
		$fields = new FieldSet(new TabSet("Root",$ArticleTabVn));
		return $fields;
	}
	public function getBanner(){
		$sqlQuery = new SQLQuery();
		$sqlQuery->select = array(
				"*",
		);
		$sqlQuery->from = array("Banner");
		$sqlQuery->where = array("Status=1");
		//$sqlQuery->limit = "1";
		$sqlQuery->orderby("Banner.Created DESC");
		$rawSQL = $sqlQuery->sql();
		$result = $sqlQuery->execute();
		$dataObject = new DataObjectSet();
		foreach($result as $row) {
			$row['Image']=ProcessFile::Link($row['BannerID']);
			$dataObject->push(new ArrayData($row));
		}
		return $dataObject;
	}
	function canCreate() {return true;}
	function canEdit() {return true;}
	function canDelete() {return true;}

}